package cn.enited.devtools.apiaggregator.api.utils;

import cn.enited.devtools.apiaggregator.api.vo.RemoteService;
import cn.enited.devtools.apiaggregator.consts.CommonConst;
import cn.hutool.core.util.StrUtil;

public final class SrvRequestUtil {

    public static boolean isGetRequest(RemoteService service) {
        return StrUtil.equalsIgnoreCase(service.getMethod(), CommonConst.HTTP_METHOD.GET);
    }

    public static boolean isPostRequest(RemoteService service) {
        return StrUtil.equalsIgnoreCase(service.getMethod(), CommonConst.HTTP_METHOD.POST);
    }

    public static boolean isPutRequest(RemoteService service) {
        return StrUtil.equalsIgnoreCase(service.getMethod(), CommonConst.HTTP_METHOD.PUT);
    }

    public static boolean isDeleteRequest(RemoteService service) {
        return StrUtil.equalsIgnoreCase(service.getMethod(), CommonConst.HTTP_METHOD.DELETE);
    }

    public static boolean isHeadRequest(RemoteService service) {
        return StrUtil.equalsIgnoreCase(service.getMethod(), CommonConst.HTTP_METHOD.HEAD);
    }

    public static boolean requestBodyIsPossible(RemoteService service) {
        return  isPostRequest(service) || isPutRequest(service) || isDeleteRequest(service);
    }

    public static boolean requestBodyIsForm(RemoteService service) {
        return StrUtil.equalsIgnoreCase(service.getDataType(), CommonConst.REQUEST_DATA_TYPE.FORM);
    }

    public static boolean requestBodyIsJson(RemoteService service) {
        return StrUtil.equalsIgnoreCase(service.getDataType(), CommonConst.REQUEST_DATA_TYPE.JSON);
    }


}
